package com.goods.controller.business;

import com.goods.business.service.SourceService;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import com.goods.common.vo.system.PageVO;
import com.google.common.base.Suppliers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/business/supplier")
public class SourceController {

    @Autowired
    private SourceService sourceService;

    /**
     * 获取供应商集合
     * @param pageNum
     * @param pageSize
     * @param name
     * @param address
     * @param contact
     * @return
     */
    @GetMapping("/findSupplierList")
    public ResponseBean<PageVO<Supplier>> findSupplierList(@RequestParam Integer pageNum,
                                                           @RequestParam Integer pageSize,
                                                           @RequestParam(value = "name",required = false) String name,
                                                           @RequestParam(value = "address",required = false) String address,
                                                           @RequestParam(value = "contact",required = false) String contact){
        PageVO<Supplier> pageVO = sourceService.findSupplierList(pageNum,pageSize,name,address,contact);
        return ResponseBean.success(pageVO);
    }

    /**
     * 添加物资来源信息
     * @param supplierVO
     * @return
     */
    @PostMapping("/add")
    public ResponseBean add(@RequestBody SupplierVO supplierVO){
        sourceService.add(supplierVO);
        return ResponseBean.success();
    }

    /**
     * 删除物资来源信息
     * @param id
     * @return
     */
    @DeleteMapping("delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        sourceService.delete(id);
        return ResponseBean.success();
    }

    /**
     * 修改物资来源信息:回显数据
     * @param id
     * @return
     */
    @GetMapping("edit/{id}")
    public ResponseBean<Supplier> getById(@PathVariable Long id){
        Supplier supplier = sourceService.getById(id);
        return ResponseBean.success(supplier);
    }

    /**
     * 修改物资来源信息
     * @param supplierVO
     * @param id
     */
    @PutMapping("update/{id}")
    public ResponseBean update(@RequestBody SupplierVO supplierVO,@PathVariable Long id){
        sourceService.update(supplierVO,id);
        return ResponseBean.success();
    }
}
